home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 November / MACPOWER-1997-11.ISO.7z / MACPOWER-1997-11.ISO / Apple関連 / ResEdit 2.1.3 / Examples / PExamples / Source / ICON.LDEF.p next >
Text File  |  1994-09-14  |  2KB  |  74 lines

  1. {
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4. }
  5. UNIT IconLDEF;
  6.  
  7. INTERFACE
  8.  
  9. Uses    MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  10.             ResEd;
  11.  
  12. PROCEDURE DrawCell( Message: INTEGER; lSelect: BOOLEAN; lRect: Rect; lCell: Point;
  13.                     lDataOffset, lDataLen: INTEGER; lh: ListHandle );
  14.  
  15. IMPLEMENTATION
  16.  
  17. PROCEDURE DrawIcon (lRect: Rect; theIcon: Handle);
  18.  
  19. CONST IconSize = 128;
  20.  
  21. BEGIN
  22. IF (SizeResource(theIcon) >= IconSize) THEN
  23.     PlotIcon(lRect, theIcon);
  24. END;
  25.  
  26. { This is the custom drawProc for the list (which contains the resource ID's).  It
  27.     simply draws the icon in the given rect and frames a selection rect around it if
  28.     told to. 
  29.     NOTE:  This is used by both ICON and ICN# pickers. }
  30. PROCEDURE DrawCell(Message: INTEGER; lSelect: BOOLEAN; lRect: Rect; lCell: Point;
  31.                    lDataOffset, lDataLen: INTEGER; lh: ListHandle);
  32.  
  33. VAR
  34.     theIcon: Handle;
  35.     id: INTEGER;
  36.     wasLoaded: BOOLEAN;
  37.     
  38.     { This routine simply looks up in the list at the given cell, extracts the ID and
  39.         gets the resource called for.  Returns NIL if not found.  Note, this assumes
  40.         the resfile is set up correctly }
  41.     FUNCTION  IconFetch(lCell: point; lHandle: ListHandle): Handle ;
  42.  
  43.     VAR
  44.         len: INTEGER;
  45.         err: OsErr;
  46.         tempH:Handle;
  47.         
  48.     BEGIN
  49.     IconFetch := NIL;
  50.     len:=2;
  51.     LGetCell(@id, len, lCell, lHandle);    { Get the ID from the list. }
  52.     IF len > 0 THEN
  53.         BEGIN    { Load the resource since we want to draw it. }
  54.         tempH := REGet1ResourceSpecial(PickHandle(lHandle^^.refCon)^^.theResFile, PickHandle(lHandle^^.refCon)^^.rType, id, wasLoaded, err);
  55.         IconFetch := tempH;
  56.         END;
  57.     END;
  58.  
  59. BEGIN    { DrawCell }
  60. CASE  message OF
  61.     lDrawMsg, lHiliteMsg:
  62.         BEGIN
  63.         theIcon := IconFetch(lCell, lh);
  64.  
  65.         DrawLDEF (message, lSelect, lRect, theIcon, id, '', 32, 32, @DrawIcon, lh);
  66.         
  67.         IF (theIcon <> NIL) & (NOT wasLoaded) THEN
  68.             HPurge(theIcon);
  69.         END;
  70.     END;
  71. END;
  72.  
  73. END.
  74.